<?php


namespace App\Controller\Admin;


use App\Annotation\OperationLog;
use App\Controller\AbstractController;
use App\Request\Admin\UserEmployerCreateRequest;
use App\Request\Admin\UserEmployerIndexRequest;
use App\Request\Admin\UserEmployerSetBalanceRequest;
use App\Service\Admin\UserEmployerService;
use Hyperf\Di\Annotation\Inject;

class UserEmployerController extends AbstractController
{

    /**
     * @Inject()
     * @var UserEmployerService
     */
    protected $userEmployerService;

    /**
     * @OperationLog(event="获取悬赏主列表",platform="admin")
     * @return mixed|\Psr\Http\Message\ResponseInterface
     */
    public function index(UserEmployerIndexRequest $request)
    {
        $where = $request->validated();
        $index = $this->userEmployerService->index($where);
        return $this->response->success($index);
    }

    /**
     * @OperationLog(event="添加悬赏主",platform="admin")
     * @param UserEmployerCreateRequest $request
     * @throws \Exception
     */
    public function create(UserEmployerCreateRequest $request){
        $validated = $request->validated();
        $userEmployer = $this->userEmployerService->create($validated);
        return $this->response->success($userEmployer);
    }

    /**
     * @OperationLog(event="冻结悬赏主账号",platform="admin")
     * @param int $userEmployerId
     * @return mixed|\Psr\Http\Message\ResponseInterface
     */
    public function block(int $userEmployerId)
    {
        $this->userEmployerService->block($userEmployerId);
        return $this->response->success();
    }

    /**
     * @OperationLog(event="解冻悬赏主账号",platform="admin")
     * @param int $userEmployerId
     * @return mixed|\Psr\Http\Message\ResponseInterface
     */
    public function unblock(int $userEmployerId)
    {
        $this->userEmployerService->unblock($userEmployerId);
        return $this->response->success();
    }

    /**
     * @OperationLog(event="设置悬赏主金额",platform="admin")
     * @param int $userEmployerId
     * @param UserEmployerSetBalanceRequest $request
     * @return mixed|\Psr\Http\Message\ResponseInterface
     */
    public function setBalance(int $userEmployerId,UserEmployerSetBalanceRequest $request)
    {
        $validated = $request->validated();
        $employer = $this->userEmployerService->setBalance($userEmployerId,$validated['balance']);
        return $this->response->success($employer);
    }
}